<?
include 'includes/specs_functions.php';
echo printGoogleAnalytics();
#----------------------------------------------------
# Connect to PADS
$DB = getDB();
#-------------------------------$Session information
$SESSION = get_session($DB);
$CICUID = $SESSION->Character;
$THEME = $_POST["THEME"];
#---------------------------------------------------


if ($CICUID != ""){

	$output = "
				<script>
					$(document).ready(function(){
						
						$('.own-empty-spec-show').click(function(e) {
								var tr = $(this).closest('tr');
								var specId = tr.attr('id');
								editSpec();
						});
							
						$('.spec-show-menu').click(function(e) {	
							$('.spec-menu').remove();
							var tr = $(this).closest('tr');
							//tr.addClass('spec-row-static');
							var id = tr.attr('id');
							id = id.substring(3);
							var name = tr.attr('name');
							var menu_label = 'Publish';
							var menu_class = 'own-spec-publish';
							if(name != 'N'){
								var menu_label = 'Hide';
								var menu_class = 'own-spec-unpublish';
							}
							
							
							var menu_row = $(' \
							<tr id=\"'+id+'\" class=\"spec-menu\">  \
								<td align=\"left\" width=\"100%\" colspan=\"4\">  \
									<div class=\"fl-right\" style=\"margin-left:10px;\">  \
										<strong class=\"with-tooltip '+menu_class+' cur-point\" title=\"'+menu_label+' spec\" style=\"font-size:10px;color: #5B5B5B;\">'+menu_label+'</strong>  \
									</div>  \
									<div class=\"own-spec-show fl-right\" style=\"margin-left:10px;\">   \
										<strong class=\"with-tooltip cur-point\" title=\"Edit spec\" style=\"font-size:10px;color: #5B5B5B;\">Edit</strong>  \
									</div>  \
									<div class=\"own-spec-delete fl-right\" >  \
										<strong class=\"with-tooltip cur-point\" title=\"Delete spec\" style=\"font-size:10px;color: #5B5B5B;\">Delete</strong>  \
									</div>  \
								</td>  \
							</tr>');
							
							menu_row.hide().insertAfter('#tr_'+id).fadeIn();
							//$('#tr_'+id).after(menu_row);
							//menu_row.fadeIn();
							addEvents();
						});
						
						function removeEvents(){
							$('.own-spec-publish').unbind('click');
							$('.own-spec-unpublish').unbind('click');
							$('.own-spec-show').unbind('click');
							$('.own-spec-delete').unbind('click');
						
						}
						
						function addEvents(){
							$('.own-spec-publish').click(function(e) {	
								var tr = $(this).closest('tr');
								var id = tr.attr('id');
								togglePublishSpecWidget(id, 'Y');
							});
							$('.own-spec-unpublish').click(function(e) {	
								var tr = $(this).closest('tr');
								var id = tr.attr('id');
								togglePublishSpecWidget(id, 'N');
							});
							$('.own-spec-show').click(function(e) {
								var tr = $(this).closest('tr');
								var specId = tr.attr('id');
								editSpec(specId);
							});
							$('.own-spec-delete').click(function(e) {	
								var tr = $(this).closest('tr');
								var id = tr.attr('id');
								deleteSpec(id);
							});
						}
						
					});
				</script>
				<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\" id=\"own_specs\">";

				$table = SPEC_TBL_SPECS." as spec";
				$col = array("spec.".SPEC_TBL_SPECS_ID." as specId"
					   ,"spec.".SPEC_TBL_SPECS_USER_ID." as userId"
					   ,"spec.".SPEC_TBL_SPECS_LAYOUT." as layout"
					   ,"spec.".SPEC_TBL_SPECS_JOB_ID." as jobId"
					   ,"spec.".SPEC_TBL_SPECS_LEVEL." as level"
					   ,"spec.".SPEC_TBL_SPECS_DESCRIPTION." as description"
					   ,"spec.".SPEC_TBL_SPECS_PUBLIC." as public"
					   ,"spec.".SPEC_TBL_SPECS_CDATE." as cdate"
					   ,"DATE_FORMAT(spec.".SPEC_TBL_SPECS_UDATE.",'%b %d %Y') as udate");
				$where = array("spec.".SPEC_TBL_SPECS_USER_ID." = \"".$CICUID."\"");
				$orderBy = "spec.".SPEC_TBL_SPECS_ID;
				$direction = "ASC";
				
				$result = $DB->GetData($table ,$col ,true ,$where, $orderBy, $direction);
				
				
				$max = 7;
				$num = $result[0];	
				$i = 1;
				$rest = $max - $num;
				
				foreach ($result[3] as $row) {
				
				$jobName = GetClass($row['jobId']);
				
			
				if($row['public'] == 'Y'){
					$col = "#0D7700";
					$status = "public";
				}else{
					$col = "#DB0000";
					$status = "hidden";
				}
			
					$output .= "
						<tr id='tr_".$row['specId']."' name='".$row['public']."' class='spec-row-hover cur-point spec-show-menu'>
							<td  align=\"left\" width=\"10%\" style='font-size:10px;'>
								".$row['level']."
							</td>
							<td  align=\"left\" width=\"10%\">
								<span class=\"with-tooltip\" title=\"".str_replace("\"", "'", $row['description'])."\"><img src='".GetClassIcon($jobName)."' style='width:18px;'/></span>
							</td>
							<td width=\"30%\">
								<strong style='font-size:11px'>".$jobName."</strong>
							</td>
							<td  width='35%' align='right' valign='middle' style='font-size:9px;color:".$col.";'>
								".$status."
							</td>
						</tr>";
						
					if($i == $max){
						break;
					}	
					
					$i++;
					
				}
				if ($rest > 0){
				
					for ($i = 1; $i <= $rest; $i++) {
						
						$output .= "
						<tr id='' class='spec-row-hover own-empty-spec-show cur-point'>
							<td align=\"left\" width=\"10%\">
							</td>
							<td align=\"left\" width=\"10%\">
								<span class=\"with-tooltip\" title='Create a spec'><img src='specs/media/no-av.png' style='width:18px;'/></span>
							</td>
							<td width=\"30%\">
								<strong style=\"font-size:10px;color: #C4C4C4;\">Empty-Slot</strong>
							</td>
							<td width='35%' align='right' valign='middle' style='font-size:9px;'>
							</td>
						</tr>";
					}
				}
			
		$output .= "	</table>";

	echo  $output;
}else{
	echo "Please login to see your specs!!!";
}

#------------------------------------------------------------------------
# Disconnect
leaveDB($DB);


?>